package com.weixiao.controller;

import com.weixiao.result.Result;
import com.weixiao.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * author 韩诚
 * date 2022/10/27
 */
@RestController
@RequestMapping("/api/oss/file")
public class FileApiController {
    @Autowired
    private FileService fileService;

    /**
     * 上传文件到阿里云oss
     *
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping("fileUpload")
    public Result fileUpload(MultipartFile file) throws IOException {
        //获取上传文件
        String url = fileService.upload(file);
        //返回文件路径
        return Result.ok(url);
    }
}